package main;

import java.io.Serializable;

/**
 * Choice is either Rock, scissors or paper.
 */
public class Choice implements Serializable, Comparable<Choice>{

	private static final long serialVersionUID = 1762508359668263711L;
	public static int ROCK = 0, PAPER = 1, SCISSORS = 2;
	private int choice;
	
	public Choice(int choice)
	{
		this.choice = choice;
	}
	
	public void setChoice(int choice)
	{
		this.choice = choice;
	}
	
	public void setChoiceRock()
	{
		this.choice = ROCK;
	}
	
	public void setChoicePaper()
	{
		this.choice = PAPER;
	}
	
	public void setChoiceScissors()
	{
		this.choice = SCISSORS;
	}
	
	public int getChoice()
	{
		return this.choice;
	}

	
	/**
	 * Returns 1 if choice wins over argument 
	 * Returns 0 if choice are the same as argument
	 * Returns -1 if choice loses to argument
	 **/
	
	@Override
	public int compareTo(Choice c)
	{
		// Equal
		if(this.choice == c.getChoice())
			return 0;
		// Rock beats scissors
		else if (this.choice == ROCK && c.getChoice() == SCISSORS)
			return 1;
		// Paper beats rock
		else if (this.choice == PAPER && c.getChoice() == ROCK)
			return 1;
		// Scissors beats paper
		else if (this.choice == SCISSORS && c.getChoice() == PAPER)
			return 1;
		// We lose to argument choice
		else 
			return -1;
	}
	
	@Override
	public String toString()
	{
		if (getChoice() == ROCK)
			return "Rock";
		else if (getChoice() == PAPER)
			return "Paper";
		else if (getChoice() == SCISSORS)
			return "Scissors";
		else
			return "Undefined";		
	}
	

}
